package calorie.com.calorie.util;

public class MaxMinUtils {
   public static MaxMin FindMaxAndMin(Float[] input, int start, int end) {
        MaxMin result = new MaxMin();
        if (end - start <= 1) {
            if (input[start] > input[end]) {

                result.max = input[start];
                result.min = input[end];
            } else {
                result.max = input[end];
                result.min = input[start];
            }
            return result;
        }

        MaxMin front = FindMaxAndMin(input, start, start + (end - start) / 2);
        MaxMin rear = FindMaxAndMin(input, start + (end - start) / 2 + 1, end);

        if (front.max > rear.max) {
            result.max = front.max;
        } else {
            result.max = rear.max;
        }

        if (front.min < rear.min) {
            result.min = front.min;
        } else {
            result.min = rear.min;
        }

        return result;

    }

    public static class MaxMin {
        public float max;
        public float min;
    }
}



